"use server";
import Title from "antd/es/typography/Title";
import Link from "next/link";
import {Divider, Drawer, Flex, message} from "antd";
import { listQuestionBankVoByPageUsingPost } from "@/api/questionBankController";
import QuestionBankList from "@/components/QuestionBankList";
import QuestionList from "@/components/QuestionList";
import {listQuestionVoByPageUsingPost} from "@/api/questionController";

export default async function HomePage() {
  let questionBankList: string[] | undefined = [];
  let questionList: API.QuestionVO[] | undefined = [];

  try {
    const res = await listQuestionBankVoByPageUsingPost({
      pageSize: 12,
      sortField: "createTime",
      sortOrder: "descend",
    });
    questionBankList = res.data.records ?? [];
  } catch (e) {
    message.error("获取题库失败");
  }

   try {
    const res = await listQuestionVoByPageUsingPost({
      pageSize: 12,
      sortField: "createTime",
      sortOrder: "descend",
    });
    questionList = res.data.records ?? [];

  } catch (e) {
    message.error("获取题库失败");
  }

  return (
    <div id="homePage" className="max-width-content">
      <Flex justify="space-between" align={"center"}>
        <Title level={3}>最新题库</Title>
        <Link href={"/banks"}>查看更多</Link>
      </Flex>
      <QuestionBankList questionBankList={questionBankList} />

      <Divider />

      <Flex justify="space-between" align={"center"}>
        <Title level={3}>最新题目</Title>
        <Link href={"/banks"}>查看更多</Link>
      </Flex>
      <QuestionList questionList={questionList} />
    </div>
  );
}
